﻿@model EmailSender.Models.SendEmailModel
@using EmailSender.Models
@using Kendo.Mvc.UI
@{
    ViewBag.Title = "ارسال ایمیل";      
}

<div class="@(string.IsNullOrEmpty(Model.ResultMessage) ? " " : "alert alert-warning col-sm-11")">@Model.ResultMessage</div>
@using (Html.BeginForm("Index", "SendEmail", FormMethod.Post, new { @class = "form-horizontal" }))
{
    int i = 0;
    @Html.ValidationSummary(true)

    @Html.Hidden("skipCount", null, new { value = Model.SkipCount })
    @Html.Hidden("EmailAddress", null, new { value = "", id = "EmailAddress" })

    <div class="form-group">
        <label class="col-sm-2 control-label" for="Category">انتخاب دسته بندی</label>
        <div class="col-sm-9">
            @Html.DropDownListFor(d => d.CategoryId, (ViewBag.Categories as List<CategoryModel>)
                .Select(s => new SelectListItem { Text = s.CatTitle, Value = s.ID.ToString() }), new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label" for="SmtpServer">انتخاب سرور</label>
        <div class="col-sm-9">
            @Html.DropDownListFor(d => d.SmtpServerId, (ViewBag.SmtpServers as List<SmtpServerModel>)
                .Select(s => new SelectListItem { Text = s.ServerName, Value = s.ID.ToString() }), new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label" for="SmtpCredential">انتخاب حساب کاربری</label>
        <div class="col-sm-9">
            @Html.DropDownListFor(d => d.SmtpCredentialId, (ViewBag.SmtpCredentials as List<SmtpCredentialModel>)
                .Select(s => new SelectListItem { Text = s.Title, Value = s.ID.ToString() }), new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label" for="SmtpCredential">موضوع ایمیل</label>
        <div class="col-sm-9">
            @Html.TextBox("Subject", "", new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label" for="editor">محتوای ایمیل</label>
        <div class="col-sm-9">
            @(Html.Kendo().Editor()
                  .Name("Body")
                  .Tools(tools => tools
          .Clear()
          .Bold().Italic().Underline().Strikethrough()
          .JustifyLeft().JustifyCenter().JustifyRight().JustifyFull()
          .InsertUnorderedList().InsertOrderedList()
          .Outdent().Indent()
          .CreateLink().Unlink()
          .InsertImage()
          .SubScript()
          .SuperScript()
          .TableEditing()
          .ViewHtml()
          .Formatting()
          .FontName()
          .FontSize()
          .FontColor().BackColor()
      ).Encode(false)
                  .HtmlAttributes(new { style = "width: 700px;height:480px" })
                  .Value(@<text>
            <div style="text-align: right">
                ...
            </div>
            </text>))
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label" for="EmailAddressGrid">
            لیست ایمیل ها                   
        </label>
        <div class="col-sm-9 k-rtl">
            @(Html.Kendo().Grid<EmailAddressModel>().Name("EmailAddressGrid").
                  Columns(columns =>
                  {
                      //columns.Command(c => c.Custom("select").).Width(80);                                            
                      columns.Bound(c => c.EmailAddress).Title("آدرس ایمیل");
                  }
                  )
                  .Groupable()
                  .Sortable()
                  .Selectable(selection => selection.Mode(GridSelectionMode.Multiple).Type(GridSelectionType.Row))
                  .Events(e => e.Change("onChange"))
                  .Editable(editing => editing.Mode(GridEditMode.InCell))
                  .ToolBar(toolbar =>
                  {
                      toolbar.Save(); // add save button to grid toolbar
                  })
                  .Pageable(pageable => pageable
                      .ButtonCount(5))
                  .DataSource(dataSource => dataSource
                      .Ajax()
                      .ServerOperation(false)
                      .Read(read => read.Action("EmailAddress_Read", "SendEmail", new { categoryId = Model.CategoryId, SkipCount = Model.SkipCount })).PageSize(80)
                      .Update(update => update.Action("Edit", "EmailAddress"))
                      .Model(m => m.Id(c => c.ID))
                  ))


        </div>
    </div>   
    <div class="checkbox" style="width: 120px">
        <label>
            <input type="checkbox" id="chkAutoSend" value="yes" />
            ارسال اتوماتیک
        </label>
    </div>

    <div class="form-group">
        <input type="submit" value="ارسال ایمیل" class="btn btn-success" />
    </div>
}

@section Scripts {
 @*   <link href="/Content/Gridmvc.css" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/gridmvc.min.js")"></script>
    <script src="@Url.Content("~/Scripts/sendEmail.js")" ></script>

    <link href="/Content/web/kendo.common.min.css" rel="stylesheet">
    <link href="/Content/web/kendo.rtl.min.css" rel="stylesheet">
    <link href="/Content/web/kendo.default.min.css" rel="stylesheet">


    <script src="/Scripts/kendo.web.min.js"></script>
    <script src="/Scripts/kendo.aspnetmvc.min.js"></script>
    <script src="/Scripts/kendo.timezones.min.js"></script>

    <script src="/Scripts/console.js"></script>
    <script src="/Scripts/prettify.js"></script>

    <script src="/Scripts/cultures/kendo.culture.fa-IR.min.js"></script>

    <script>
        kendo.culture("fa-IR");
    </script>*@


}
